package com.genius.reservation.driver.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.genius.reservation.car.entity.ReservationStartCarInformation;
import com.genius.reservation.common.ResponseRule;
import com.genius.reservation.common.constant.Constant;
import com.genius.reservation.common.constant.ResStatusCode;
import com.genius.reservation.common.rabbitmq.RabbitMessageEntity;
import com.genius.reservation.common.rabbitmq.RabbitService;
import com.genius.reservation.driver.entity.DriverInformation;
import com.genius.reservation.driver.service.IDriverInformationService;
import com.genius.reservation.evaluate.entity.EvaluateInformation;
import com.genius.reservation.evaluate.service.IEvaluateInformationService;
import com.genius.reservation.mapper.CarInformationMapper;
import com.genius.reservation.mapper.DriverInformationMapper;
import com.genius.reservation.mapper.PlatformInformationMapper;
import com.genius.reservation.mapper.ReservationStartCarInformationMapper;
import com.genius.reservation.plague.entity.PlagueInformation;
import com.genius.reservation.plague.service.IPlagueInformationService;
import com.genius.reservation.platform.entity.PlatformInformation;
import com.genius.reservation.receiver.entity.ReceiverInformation;
import com.genius.reservation.receiver.service.IReceiverInformationService;
import com.genius.reservation.reservation.entity.ReservationInformation;
import com.genius.reservation.reservation.service.IReservationInformationService;
import com.genius.reservation.tools.SendWXMsg;
import com.genius.reservation.tools.annotation.webLog;
import com.genius.reservation.user.entity.UserInformation;
import com.genius.reservation.user.service.IUserInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 司机信息表 服务实现类
 * </p>
 *
 * @author baomidou
 * @since 2022-05-26
 */
@Service
public class DriverInformationServiceImpl extends ServiceImpl<DriverInformationMapper, DriverInformation> implements IDriverInformationService {

    @Autowired
    DriverInformationMapper driverMapper;
    @Autowired
    CarInformationMapper carMapper;
    @Autowired
    IPlagueInformationService plagueService;

    @Autowired
    @Lazy
    IReservationInformationService reservationService;

    @Autowired
    RabbitService rabbitService;

    @Autowired
    IEvaluateInformationService evaService;

    @Autowired
    @Lazy
    IUserInformationService userService;

    @Autowired
    SendWXMsg sendWXMsg;

    @Autowired
            @Lazy
    IReceiverInformationService receiverInformationService;
    @Autowired
    @Lazy
    ReservationStartCarInformationMapper reservationStartCarMapper;

    @Autowired
    @Lazy
    IReservationInformationService reservationMapper;

    @Autowired
    @Lazy
    PlatformInformationMapper platformMapper;

    public static Map<String, RabbitMessageEntity> message = new HashMap<>();

    @Override
    @Transactional(rollbackFor = Exception.class)
    public DriverInformation newDriver(UserInformation user) {
        DriverInformation driverInformation = new DriverInformation();
        driverInformation.setDriverNumber(Constant.DRIVER_PREFIX + IdUtil.randomUUID());
        driverInformation.setDriverName(user.getName());
        driverInformation.setUserNumber(user.getUserNumber());
        driverInformation.setSupplierNumber(user.getSupplierNumber());
        return this.addAndUp(driverInformation);
    }

    @Override
    public ResponseRule selectDriver(String driverNumber) {
        DriverInformation driverInformation = driverMapper.selectByDriverNumber(driverNumber);
        return ResponseRule.ok(driverInformation);
    }

    @Override
    public DriverInformation selectOneDriver(String driverNumber) {
        return driverMapper.selectByDriverNumber(driverNumber);
    }

    @Override
    public List<DriverInformation> getList() {
        List<DriverInformation> list = driverMapper.getList();
        return list;
    }


    @Override
    @webLog
    @Transactional(rollbackFor = Exception.class)
    public ResponseRule unbind(String driverNumber) {
        DriverInformation driverInformation = driverMapper.selectByDriverNumber(driverNumber);
        driverInformation.setCar(null);
        driverInformation.setCarNumber(null);
        if (this.saveOrUpdate(driverInformation))
            return ResponseRule.ok(driverInformation, "解绑成功");
        return ResponseRule.no("解绑失败");
    }

    @Override
    public ResponseRule editDriver(DriverInformation driver) {
        DriverInformation driverInformation = driverMapper.selectByDriverNumber(driver.getDriverNumber());
        driverInformation.setDriverSex(driver.getDriverSex());
        driverInformation.setDriverName(driver.getDriverName());
        if (this.saveOrUpdate(driverInformation))
            return ResponseRule.ok(driverInformation, "修改成功");
        return ResponseRule.no("修改失败");
    }

    @Override
    public ResponseRule bindPlague(Map<String, String> body) {
        PlagueInformation plagueInformation = new PlagueInformation();
        plagueInformation.setDriverNumber(body.get("driverNumber"));
        plagueInformation.setPlagueNumber(Constant.PLAGUE_PREFIX + IdUtil.randomUUID());
        plagueInformation.setDnaReport(body.get("dnaReport"));
        plagueInformation.setHealthyCode(body.get("healthyCode"));
        plagueInformation.setTripCard(body.get("tripCard"));
        try {
            PlagueInformation re = plagueService.saAndUp(plagueInformation);
            return ResponseRule.ok(re, "三码跟随成功");
        } catch (Exception e) {
            return ResponseRule.no("三码跟随失败");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseRule setOut(String reservationNumber, Integer startCarId) {
        synchronized (this) {
            boolean flag = true;
            LambdaQueryWrapper<ReservationStartCarInformation> eq = reservationStartCarMapper.getWrapper().eq(ReservationStartCarInformation::getReservationNumber, reservationNumber).eq(ReservationStartCarInformation::getNowStatus, ResStatusCode.RESERVATION_CONFIRM);
            List<ReservationStartCarInformation> drivers = reservationStartCarMapper.selectList(eq);
            if (ObjectUtil.isEmpty(drivers)) {
                return ResponseRule.no("未找到匹配的发车信息");
            }
            boolean findFlag = false;
            for (ReservationStartCarInformation driver : drivers) {
                if (Objects.equals(driver.getId(), startCarId)) {
                    driver.setNowStatus(3);
                    reservationStartCarMapper.up(driver);
                    findFlag = true;
                }
                if (driver.getNowStatus() != 3) {
                    flag = false;
                }
            }
            if(!findFlag) return ResponseRule.no("二维码错误,此车辆并不在此预约单中");
            ReservationInformation one = reservationService.getByReservationNumber(reservationNumber);
            if (one.getNowStatus() == ResStatusCode.RESERVATION_SETOUT || one.getNowStatus() != ResStatusCode.RESERVATION_CONFIRM)
                return ResponseRule.no("发车失败,状态异常");
            if (flag) {
                one.setNowStatus(ResStatusCode.RESERVATION_SETOUT);
                ReservationInformation reservationInformation = reservationService.addAndUp(one);
                //更新二维码
                reservationInformation.setQRCode(null);
                RabbitMessageEntity<Object> obj = new RabbitMessageEntity<>();
                obj.setData(reservationInformation);
                obj.setMsg(String.format("预约全部车辆已发车,单号为:%s", reservationNumber));
                obj.setReservationNumber(reservationNumber);
                rabbitService.ToReceiverManager(obj);
                rabbitService.ToSupplier(obj);
                String supplierWxNumber = userService.getUserByUserNumber(one.getSupplierNumber()).getWxNumber();
                sendWXMsg.sendMsg(supplierWxNumber, "物流运送","全部车辆已发车", one.getConfirmArrivalTime(), "pages/index/main");
                return ResponseRule.ok(reservationInformation, "确认发车成功,订单内所有车辆已发车");
            } else {
                return ResponseRule.ok("确认发车完成");
            }
        }
        //做到预约车辆发车了
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseRule arriveSubmit(String reservationNumber, Integer startCarId) {
        //标志位
        boolean flag = true;
        //迟到
        boolean timeout = true;
        //所有都送完了
        boolean isCheck = false;
        HashMap<String, Object> timeObj = new HashMap<>();
        //获取提交到达信息的发车信息
        LambdaQueryWrapper<ReservationStartCarInformation> eq = reservationStartCarMapper.getWrapper().
                eq(ReservationStartCarInformation::getReservationNumber, reservationNumber);
        List<ReservationStartCarInformation> drivers = reservationStartCarMapper.selectList(eq);
        System.out.println(drivers);
        if (ObjectUtil.isEmpty(drivers)) {
            return ResponseRule.no("未找到司机信息");
        }

        ReservationInformation one = reservationService.getByReservationNumber(reservationNumber);

        for (ReservationStartCarInformation driver : drivers) {

            if (Objects.equals(driver.getId(), startCarId)) {

                if (driver.getNowStatus() == ResStatusCode.RESERVATION_FINISH || driver.getNowStatus() == ResStatusCode.RESERVATION_ARRIVE ||driver.getNowStatus() == ResStatusCode.START_RECEIVE) {
                    isCheck = true;
                }
                //当前状态
                timeObj.put("nowStatus",driver.getNowStatus());
                //获取预约时间
                DateTime confirm = new DateTime(one.getConfirmArrivalTime());
                //获取到达时间
                DateTime actual = DateTime.now();
                driver.setActualArrivalTime(actual.toString());

                //计算时间
                long between = DateUtil.between(confirm, actual, DateUnit.MINUTE,false);

                LambdaQueryWrapper<PlatformInformation> eq1 = platformMapper.getWrapper().eq(PlatformInformation::getPlatformNumber, driver.getConfirmPlatformNumber());
                PlatformInformation platformInformation = platformMapper.selectOne(eq1);
                ReceiverInformation receiver = receiverInformationService.getReceiverByReceiverNumber(driver.getActualReceiverNumber());

                if(between>0){
                    //迟到
                    if (driver.getNowStatus()==ResStatusCode.RESERVATION_SETOUT){
                        driver.setTimeoutStatus(2);
                        driver.setActualArrivalTime(actual.toString());
                        timeObj.put("timeOut", 2);
                    }
                    if(0-(-between)<=60){
                        //迟到一小时之内
                        timeObj.put("timeOutMsg", "您已迟到" +( 0-(-between)) + "分钟");
                        IsFree(timeObj, driver, platformInformation, receiver);
                    }else{
                        //迟到一小时以上
                        long between1 = 0-(-DateUtil.between(confirm, actual, DateUnit.HOUR, false));
                        timeObj.put("timeOutMsg", "迟到" + between1 + "小时");
//                        IsFree(timeObj, driver, platformInformation, receiver);
                        timeObj.put("receiveMsg", "抱歉,您的预约已超时,无法进入,请联系主管!");
                        timeObj.put("receiverManagerPhone", driver.getReceiverManagerPhone());
                        timeObj.put("platformStatus", 1);
                        timeObj.put("goInto", 1);
                    }
                }else {
                    //早到
                    if(0-(between)<=60) {
                        if (driver.getNowStatus() == ResStatusCode.RESERVATION_SETOUT) {
                            timeObj.put("timeOut", 0);
                            driver.setTimeoutStatus(0);
                            driver.setActualArrivalTime(actual.toString());
                        }
                        timeObj.put("timeOutMsg", "非常感谢您的准时");
                        IsFree(timeObj, driver, platformInformation, receiver);
                    }else{
                        if (driver.getNowStatus() == ResStatusCode.RESERVATION_SETOUT) {
                            timeObj.put("timeOut", 1);
                            driver.setTimeoutStatus(1);
                            driver.setActualArrivalTime(actual.toString());
                        }
                        long between1 = 0-(DateUtil.between(confirm, actual, DateUnit.HOUR, false));
                        timeObj.put("timeOutMsg", "早到"+between1+"小时");
                        timeObj.put("receiveMsg", "抱歉,您已提前到达,无法进入,请联系主管!");
                        timeObj.put("receiverManagerPhone", driver.getReceiverManagerPhone());
                        timeObj.put("platformStatus", 1);
                        timeObj.put("goInto", 1);
                    }
                }
                //只是查询时间
                if (isCheck) {
                    return ResponseRule.ok(timeObj);
                }

                driver.setNowStatus(ResStatusCode.RESERVATION_ARRIVE);//已到达
                reservationStartCarMapper.up(driver);

            }

            if (driver.getNowStatus() != 4) {
                flag = false;
            }
            if (driver.getTimeoutStatus() == 2) {
                timeout = false;
            }

        }
            /*
				结构：{
					timeOut:0, 正常0  超时 1  提前 2
					timeOutMsg:"提前xxx到达",
					platformStatus:空闲0  占用1
					goInto:0 进入  1 不进入  2进入等待
				}
				*/


        if (flag) {
            if (timeout) {
                one.setTimeoutStatus(1);
            } else {
                one.setTimeoutStatus(2);
            }
            one.setNowStatus(ResStatusCode.RESERVATION_ARRIVE);
            //更新二维码
            one.setQRCode(null);
            ReservationInformation reservationInformation = reservationService.addAndUp(one);

            //发送通知
            RabbitMessageEntity<Object> obj = new RabbitMessageEntity<>();
            obj.setData(reservationInformation);
            obj.setMsg(String.format("预约全部车辆已到达,单号为:%s", reservationNumber));
            obj.setReservationNumber(reservationNumber);
            rabbitService.ToReceiverManager(obj);
            rabbitService.ToSupplier(obj);
            timeObj.put("startCarId",startCarId);
            //订阅
            String supplierWxNumber = userService.getUserByUserNumber(one.getSupplierNumber()).getWxNumber();
            sendWXMsg.sendMsg(supplierWxNumber, "物流运送","全部车辆已到达", one.getConfirmArrivalTime(), "pages/index/main");
            return ResponseRule.ok(timeObj, "确认到达成功,订单内所有车辆均已到达");
        } else {
            return ResponseRule.ok(timeObj, "确认到达成功");
        }
    }

    //判断到达时间和状态
    private void IsFree(HashMap<String, Object> timeObj, ReservationStartCarInformation driver, PlatformInformation platformInformation, ReceiverInformation receiver) {

        if (platformInformation.getPlatformIsUse() == 1) {
            timeObj.put("receiveMsg", "抱歉,您预约的月台目前正在使用中,请您稍作等待或联系主管更换收货员!");
            timeObj.put("receiverManagerPhone", driver.getReceiverManagerPhone());
            timeObj.put("platformStatus", 1);
            timeObj.put("goInto", 1);
        }
        if (receiver.getIsFree() != 1) {
            if(receiver.getDutyFlag()<1){
                timeObj.put("receiveMsg", "抱歉,您预约的收货员目前正在忙碌中,请您稍作等待或联系主管更换收货员!");
            }else{
                timeObj.put("receiveMsg", "抱歉,您预约的收货员目前已离岗,请您请联系主管更换收货员!");
            }
            timeObj.put("receiverManagerPhone", driver.getReceiverManagerPhone());
            timeObj.put("receiverStatus", 1);
            timeObj.put("goInto", 1);
        }
        if (receiver.getIsFree() != 1 && platformInformation.getPlatformIsUse() == 1) {
            timeObj.put("receiveMsg", "抱歉,您预约的收货员及月台目前还在忙碌中,请您稍作等待或联系主管更换收货员及月台!");
            timeObj.put("receiverManagerPhone", driver.getReceiverManagerPhone());
            timeObj.put("receiverStatus", 1);
            timeObj.put("platformStatus", 1);
            timeObj.put("goInto", 1);
        }
        if (receiver.getIsFree() != 0 && platformInformation.getPlatformIsUse() == 0) {
            JSONObject visitorCar = new JSONObject();
            visitorCar.set("carCode",driver.getCarCode());
            visitorCar.set("phone",driver.getDriverPhone());
            visitorCar.set("name",driver.getDriverName());
            if (driver.getReserveOrderNo().equals("-1")) {
                String body = HttpRequest.post("https://visitor.jinhubianli.com/visitor/addVisitorCar").body(JSONUtil.toJsonStr(visitorCar)).execute().body();
                JSONObject result= null;
                try {
                    result = JSONUtil.parseObj(body);
                }catch (Exception e){
                    e.printStackTrace();
                    timeObj.put("receiveMsg", "抱歉,您无法进入,请您联系管理员");
                    timeObj.put("receiverManagerPhone", driver.getReceiverManagerPhone());
                    timeObj.put("platformStatus", 0);
                    timeObj.put("receiverStatus", 0);
                    timeObj.put("goInto", 1);
                    return;
                }
                if((int)result.get("code")==0){
                    timeObj.put("receiveMsg", "请您进场前往"+driver.getConfirmPlatformNumber()+"号月台装卸");
                    timeObj.put("receiverPhone", driver.getReceiverPhone());
                    timeObj.put("platformStatus", 0);
                    timeObj.put("receiverStatus", 0);
                    timeObj.put("goInto", 0);
                    JSONObject data = (JSONObject)result.get("data");
                    String reserveOrderNo = (String)data.get("reserveOrderNo");
                    driver.setReserveOrderNo(reserveOrderNo);
                    reservationStartCarMapper.up(driver);
                }else{
                    timeObj.put("receiveMsg", "抱歉,您无法进入,请您联系管理员");
                    timeObj.put("receiverManagerPhone", driver.getReceiverManagerPhone());
                    timeObj.put("platformStatus", 0);
                    timeObj.put("receiverStatus", 0);
                    timeObj.put("goInto", 1);
                }
            }else{
                    timeObj.put("receiveMsg", "请您进场前往"+driver.getConfirmPlatformNumber()+"号月台装卸");
                    timeObj.put("receiverPhone", driver.getReceiverPhone());
                    timeObj.put("platformStatus", 0);
                    timeObj.put("receiverStatus", 0);
                    timeObj.put("goInto", 0);
            }
        }
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseRule evaluate(String receiverNumber,Integer startCarId ,Integer operationScore,Integer attitudeScore,String evaluateRemarks) {
        try {
            ReservationStartCarInformation carInformation = reservationStartCarMapper.selectById(startCarId);
            if (ObjectUtil.isEmpty(carInformation)) {
                ResponseRule.no("没有找到车辆");
            }

            carInformation.setIsEvaluate(1);

            reservationStartCarMapper.up(carInformation);

            ReservationInformation re = reservationService.getByReservationNumber(carInformation.getReservationNumber());
            re.setNowStatus(ResStatusCode.RESERVATION_FINISH);

            reservationService.addAndUp(re);

            if (re.getNowStatus() != ResStatusCode.RESERVATION_FINISH) return ResponseRule.no("评价失败,重复评价");

            EvaluateInformation ev = new EvaluateInformation();
            ev.setEvaluateNumber(Constant.EVALUATE_PREFIX + DateTime.now().toString().replace("-", "").replace(":", "").replace(" ", ""));
            ev.setReceiverNumber(carInformation.getActualReceiverNumber());
            ev.setEvaluateRemarks(evaluateRemarks);
            ev.setAttitudeScore(attitudeScore);
            ev.setComprehensiveScore(0);
            ev.setOperationScore(operationScore);
            ev.setStartCarId(carInformation.getId());
            evaService.addAndUp(ev);

            return ResponseRule.ok("评价完成");
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return ResponseRule.no("评价失败,服务器错误");
        }

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseRule bindSupplier(String driverNumber, String supplierCode) {
        try {
            DriverInformation driverInformation = driverMapper.selectByDriverNumber(driverNumber);
            driverInformation.setSupplierNumber(supplierCode);
            DriverInformation driver = this.addAndUp(driverInformation);
            return ResponseRule.ok(driver, "绑定供应商成功");
        } catch (Exception e) {
            System.out.println(e);
            return ResponseRule.no("绑定供应商失败");
        }
    }

    @Override
    public ResponseRule getDriverBySupplier(String supplierNumber) {
        List<DriverInformation> listBySupplier = driverMapper.getListBySupplier(supplierNumber);
        return ResponseRule.ok(listBySupplier);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)

    public ResponseRule driverSubmit(Integer startCarId, String wxNumber, String carCode, String driverName, String phone, String setOutPlace, String[] carImg, String[] healthyImg, String startCarTime, String reservationNumber) {
        ReservationStartCarInformation startCar=null;
        LambdaQueryWrapper<ReservationStartCarInformation> eq = reservationStartCarMapper.getWrapper().eq(ReservationStartCarInformation::getReservationNumber, reservationNumber).eq(ReservationStartCarInformation::getCarCode, carCode);
        startCar= reservationStartCarMapper.selectOne(eq);
        if(ObjectUtil.isEmpty(startCar)){
            startCar = reservationStartCarMapper.selectById(startCarId);
        }
        if (startCar.getNowStatus()==ResStatusCode.RESERVATION_SETOUT)
            return ResponseRule.no("此车辆已出发,请勿重复填写");
        startCar.setDriverWxNumber(wxNumber);
        startCar.setDriverPhone(phone);
        startCar.setDriverName(driverName);
        startCar.setCarCode(carCode);
        startCar.setStartAddress(setOutPlace);
        startCar.setStartCarTime(startCarTime);
        StringBuilder newCarImg = new StringBuilder();
        StringBuilder healthImg = new StringBuilder();
        for (String s : carImg) {
            newCarImg.append(s).append("卍");
        }
        newCarImg = new StringBuilder(StrUtil.sub(newCarImg.toString(), 0, newCarImg.length() - 1));
        startCar.setCarImg(newCarImg.toString());
        for (String s : healthyImg) {
            healthImg.append(s).append("卍");
        }
        healthImg = new StringBuilder(StrUtil.sub(healthImg.toString(), 0, healthImg.length() - 1));
        startCar.setHealthyImg(healthImg.toString());
//        ReservationInformation reservationServiceByReservationNumber = reservationService.getByReservationNumber(reservationNumber);
//        reservationServiceByReservationNumber.setNowStatus(ResStatusCode.RESERVATION_SETOUT);
        ReservationStartCarInformation reservationStartCarInformation = reservationStartCarMapper.up(startCar);
//        ReservationInformation reservationInformation = reservationService.addAndUp(reservationServiceByReservationNumber);
        return this.setOut(reservationStartCarInformation.getReservationNumber(), reservationStartCarInformation.getId());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseRule driverEdit(Integer startCarId, String wxNumber, String carCode, String driverName, String phone, String setOutPlace, String[] carImg, String[] healthyImg) {
       try {
           ReservationStartCarInformation startCar = reservationStartCarMapper.selectById(startCarId);
           startCar.setDriverWxNumber(wxNumber);
           startCar.setDriverPhone(phone);
           startCar.setDriverName(driverName);
           startCar.setCarCode(carCode);
           startCar.setStartAddress(setOutPlace);
           StringBuilder newCarImg = new StringBuilder();
           StringBuilder healthImg = new StringBuilder();
           for (String s : carImg) {
               newCarImg.append(s).append("卍");
           }
           newCarImg = new StringBuilder(StrUtil.sub(newCarImg.toString(), 0, newCarImg.length() - 1));
           startCar.setCarImg(newCarImg.toString());
           for (String s : healthyImg) {
               healthImg.append(s).append("卍");
           }
           healthImg = new StringBuilder(StrUtil.sub(healthImg.toString(), 0, healthImg.length() - 1));
           startCar.setHealthyImg(healthImg.toString());

           ReservationStartCarInformation reservationStartCarInformation = reservationStartCarMapper.up(startCar);
           return ResponseRule.ok(reservationStartCarInformation, "信息修改成功");

       }catch (Exception e){
           e.getStackTrace();
           throw  new RuntimeException("修改信息失败");
       }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseRule editDriverInformation(String wxNumber, String reservationNumber, String carCode, String driverName, String phone, String setOutPlace, String[] carImg, String[] healthyImg) {
        LambdaQueryWrapper<ReservationStartCarInformation> eq = reservationStartCarMapper.getWrapper().eq(ReservationStartCarInformation::getDriverWxNumber, wxNumber);
        ReservationStartCarInformation reservationStartCarInformation = reservationStartCarMapper.selectOne(eq);
        reservationStartCarInformation.setCarCode(carCode);
        reservationStartCarInformation.setDriverName(driverName);
        reservationStartCarInformation.setDriverPhone(phone);
        reservationStartCarInformation.setStartAddress(setOutPlace);
        StringBuilder newCarImg = new StringBuilder();
        for (String s : carImg) {
            newCarImg.append(s).append("卍");
        }
        newCarImg = new StringBuilder(StrUtil.sub(newCarImg.toString(), 0, newCarImg.length() - 2));
        reservationStartCarInformation.setCarImg(newCarImg.toString());
        StringBuilder healthImg = new StringBuilder();
        for (String s : healthyImg) {
            healthImg.append(s).append("卍");
        }
        healthImg = new StringBuilder(StrUtil.sub(healthImg.toString(), 0, healthImg.length() - 2));
        reservationStartCarInformation.setHealthyImg(healthImg.toString());
        ReservationStartCarInformation reservationStartCarInformation1 = reservationStartCarMapper.up(reservationStartCarInformation);
        if (ObjectUtil.isEmpty(reservationStartCarInformation1))
            return ResponseRule.no("用户未找到,修改信息失败");
        else {
            return ResponseRule.ok(reservationStartCarInformation1, "修改信息成功");
        }
    }

    @Override
    public ResponseRule getStartCarInformation(String reservationNumber) {
        ReservationInformation reservationServiceByReservationNumber = reservationService.getByReservationNumber(reservationNumber);
        if (ObjectUtil.isEmpty(reservationServiceByReservationNumber)) {
            return ResponseRule.no("没有找到预约单");
        } else {
            return ResponseRule.ok(reservationServiceByReservationNumber);
        }
    }

    @Override
    public ResponseRule getStartCar(String startCarId) {
        ReservationStartCarInformation carInformation = reservationStartCarMapper.selectById(startCarId);
        if (ObjectUtil.isEmpty(carInformation))
            ResponseRule.no("未找到发车信息");
        return ResponseRule.ok(carInformation);
    }


//    @Override
//    public ResponseRule arrive(String reservationNumber) {
//        ReservationInformation one = reservationService.getByReservationNumber(reservationNumber);
//        DateTime confirm = new DateTime(one.getConfirmArrivalTime());
//        DateTime actual = DateTime.now();
//
//        long between = DateUtil.between(actual, confirm, DateUnit.MINUTE);
//        HashMap<String, Object> rabbit = new HashMap<>();
//        if (actual.isBefore(confirm)) {
//            //早到
//            if (between <= -10){
//                one.setTimeoutStatus(0);
//                rabbit.put("msg",String.format("预约准时到达,单号为:%s",reservationNumber));
//            }else{
//                one.setTimeoutStatus(2);
//                rabbit.put("msg",String.format("预约提前到达,单号为:%s",reservationNumber));
//            }
//        } else {
//            //超时
//            one.setTimeoutStatus(1);
//            rabbit.put("msg",String.format("预约超时到达,单号为:%s",reservationNumber));
//        }
//        one.setActualArrivalTime(actual.toString());
//        ReservationInformation re = reservationService.actualArrivalTime(one);
//        rabbit.put("data",re);
//        rabbitService.sendArriveReservationToReceiver(rabbit);
//        return ResponseRule.ok("确认到达完成");
//    }
}
